﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace PC.AzureMultiApp.Core
{
    public class DeploymentHostServiceManager
    {
        private Deployment service;

        public DeploymentHostServiceManager()
        {
            service = new Deployment();
            ServiceHost host = new ServiceHost(service);

            string address = String.Format("http://{0}/DeploymentService", 
                RoleEnvironment.Roles["WebRoleMultiApp"].Instances.First().InstanceEndpoints
                .Where(ip => ip.Key == "NotityEndpoint").First().Value.IPEndpoint);

            BasicHttpBinding binding = new BasicHttpBinding();

            host.AddServiceEndpoint(typeof(IDeployment), (Binding)binding, address);

            host.Open();
        }


    }
}
